package com.haixiaoke.saas.manage.messageCenter.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.messageCenter.domain.PublicMessage;
import com.haixiaoke.saas.messageCenter.service.IPublicMessageService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公共消息模版信息Controller
 *
 * @author xiaolong
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/manage/messageCenter/publicMessage")
public class ManagePublicMessageController extends BaseController {
    @Autowired
    private IPublicMessageService publicMessageService;

    /**
     * 查询公共消息模版信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicMessage publicMessage) {
        startPage();
        List<PublicMessage> list = publicMessageService.selectPublicMessageList(publicMessage);
        return getDataTable(list);
    }

    /**
     * 导出公共消息模版信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PublicMessage publicMessage) {
        List<PublicMessage> list = publicMessageService.selectPublicMessageList(publicMessage);
        ExcelUtil<PublicMessage> util = new ExcelUtil<PublicMessage>(PublicMessage.class);
        util.exportExcel(response, list, "公共消息模版信息数据");
    }

    /**
     * 获取公共消息模版信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:query')")
    @GetMapping(value = "/{publicMessageId}")
    public AjaxResult getInfo(@PathVariable("publicMessageId") Long publicMessageId) {
        return success(publicMessageService.selectPublicMessageByPublicMessageId(publicMessageId));
    }

    /**
     * 新增公共消息模版信息
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:add')")
    @PostMapping
    public AjaxResult add(@RequestBody @Valid PublicMessage publicMessage) {
        publicMessage.setCreateBy(getUsername());
        return toAjax(publicMessageService.insertPublicMessage(publicMessage));
    }

    /**
     * 修改公共消息模版信息
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody @Valid PublicMessage publicMessage) {
        publicMessage.setUpdateBy(getUsername());
        return toAjax(publicMessageService.updatePublicMessage(publicMessage));
    }

    /**
     * 删除公共消息模版信息
     */
    @PreAuthorize("@ss.hasPermi('manage:publicMessage:remove')")
    @DeleteMapping("/{publicMessageIds}")
    public AjaxResult remove(@PathVariable Long[] publicMessageIds) {
        return toAjax(publicMessageService.deletePublicMessageByPublicMessageIds(publicMessageIds));
    }
}
